const _ = require('lodash');

function selfMemoize(fn) {
  const memoizeObj = {};
  return function() {
    const arg_key = JSON.stringify(arguments);
    memoizeObj[arg_key] = memoizeObj[arg_key] !== undefined ? memoizeObj[arg_key] : fn.apply(fn, arguments);
    return memoizeObj[arg_key];
  }
}
// 该函数只会被执行一次
function add(r) {
  return Math.PI * r * r;
}

// const aaa = selfMemoize(add);
const aaa = _.memoize(add);

console.log(aaa(1));
console.log(aaa(1));
console.log(aaa(1));
